﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using WorkSummary.Bussiness.Bll;
using WorkSummary.Bussiness.Model;
using WorkSummary.Common;

namespace WorkSummaryReoprter.ashx
{
    /// <summary>
    /// Task 的摘要说明
    /// </summary>
    public class Task : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            var action = context.Request["action"];
            var json = context.Request["json"];
            var sdate = context.Request["StartDate"];
            var edate = context.Request["EndDate"];
            switch (action)
            {
                case "GetAllTaskByUserID":
                    context.Response.Write(JSONhelper.ToJson(BTask.Instance.GetAllTaskByUser(sdate, edate)));
                    break;
                case "GetAllTask":
                    context.Response.Write(JSONhelper.ToJson(BTask.Instance.GetAllTask(sdate, edate)));
                    break;
                case "AddTask":
                    MTask mTask1 = JSONhelper.ConvertToObject<MTask>(json);
                    context.Response.Write(JSONhelper.ToJson(BTask.Instance.AddTask(mTask1)));
                    break;
                case "DelTask":
                    var IDs = context.Request["IDs"];
                    context.Response.Write(JSONhelper.ToJson(BTask.Instance.DelTask(IDs)));
                    break;
                case "ModifyTask":
                    MTask mTask2 = JSONhelper.ConvertToObject<MTask>(json);
                    context.Response.Write(JSONhelper.ToJson(BTask.Instance.ModifyTask(mTask2)));
                    break;
                default:
                    context.Response.Write(JSONhelper.ToJson(new { code = -1, msg = "no action matched！" }));
                    break;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}